function getInfo(){
    $.ajax({
        url : "/admin/findbook",
        type : "POST",
        data : {
            bookId : $("#inputID").val()
        },
        success : function(book){
            if(book){
                $("#inputName").val(book.bookName);
                $("#inputAuthor").val(book.author);
                $("#inputpublication").val(book.publication);
                $("#inputpublisher").val(book.publisher);
                $("#inputtypeId").val(book.typeId);
                $("#inputprice").val(book.price);
                $("#inputbookSum").val(book.bookSum);
            }else {
                alert("图书不存在");
                $("#inputName").val('');
                $("#inputAuthor").val('');
                $("#inputpublication").val('');
                $("#inputpublisher").val('');
                $("#inputtypeId").val('');
                $("#inputprice").val('');
                $("#inputbookSum").val('');
            }
        },
        error : function(){
            alert("请求错误");
        }
    })
}

$("#showPopup,#showPopup1").click(function () {
    $("#inputID").val("");
    $("#inputName").val("");
    $("#inputAuthor").val("");
    $("#inputpublication").val("");
    $("#inputpublisher").val("");
    $("#inputtypeId").val("");
    $("#inputprice").val("");
    $("#inputbookSum").val("");
    $("#inputbookId1").val("");
})

$("#btn-query").click(function (event) {
    event.preventDefault();
    let tbody = document.querySelector("#datatables tbody");
    $.ajax({
        url : '/admin/findBookByInput',
        type : 'post',
        data : {
            bookId : $("#bookId").val(),
            bookName : $("#bookName").val(),
            author : $("#author").val(),
            publisher : $("#publisher").val(),
            typeId : $("#typeId").val(),
        },
        success: function(booksData){
            tbody.innerHTML = "";
            $.each(booksData, function (index, books) {
                let row = $("<tr></tr>");
                let bookIdTd = $("<td></td>").text(books.bookId);
                let bookNameTd = $("<td></td>").text(books.bookName);
                let bookAuthorTd = $("<td></td>").text(books.author);
                let bookpublication = $("<td></td>").text(books.publication);
                let bookpublisher = $("<td></td>").text(books.publisher);
                let booktypeId = $("<td></td>").text(books.typeId);
                let bookprice = $("<td></td>").text(books.price);
                let bookSum = $("<td></td>").text(books.bookSum);
                row.append(bookIdTd);
                row.append(bookNameTd);
                row.append(bookAuthorTd);
                row.append(bookpublication);
                row.append(bookpublisher);
                row.append(booktypeId);
                row.append(bookprice);
                row.append(bookSum);
                $("#datatables tbody").append(row);
            });
        },
        error: function () {
            alert('请求发生错误，请稍后再试！');
        }
    })
})

